robustness_senior_junior_winner <- function(
  data, rdd_model, rdd_plot, est_rdd_power, permutation_analysis,
  permutation_plot
) {

  # initial binding of globals
  `%>%` <- magrittr::`%>%`
  win_cabinet <- win_largest <- win_junior <- NULL

  # split sample into senior party winners and junior party winners ---------

  # senior colition party winners
  df_winners_senior <- data %>%
    dplyr::filter(win_cabinet == 1 & win_largest == 1)

  # junior coalition party winners
  df_winners_junior <- data %>%
    dplyr::filter(win_cabinet == 1 & win_junior == 1)


  # rdd ---------------------------------------------------------------------

  # senior partners rdd model
  m_senior <- rdd_model(
    data = df_winners_senior,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date"
  )

  # rdd plot seniors
  p_senior <- rdd_plot(
    data = df_winners_senior,
    model = m_senior,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date",
    title = "Electoral Winners Senior Coalition Partners"
  )

  # rdd power seniors
  seniors_power <- est_rdd_power( # nolint
    data = df_winners_senior,
    outcome = "swd",
    running.var = "relative_date",
    cluster = "election",
    cutoff = 0,
    tau = -0.33
  )

  # junior partners rdd model
  m_junior <- rdd_model(
    data = df_winners_junior,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date"
  )

  # rdd plot juniors
  p_juniors <- rdd_plot(
    data = df_winners_junior,
    model = m_junior,
    outcome = "swd",
    clustervar = "election",
    running.var = "relative_date",
    title = "Electoral Winners Junior Coalition Partners"
  )

  # rdd power juniors
  juniors_power <- est_rdd_power( # nolint
    data = df_winners_junior,
    outcome = "swd",
    running.var = "relative_date",
    cluster = "election",
    cutoff = 0,
    tau = -0.3
  )

  # permutation analysis ----------------------------------------------------

  # seniors
  message("Permutation analysis seniors")
  m2_seniors <- permutation_analysis( # nolint
    data = df_winners_senior,
    min_day = plyr::round_any(
      x = - m_senior$bws["b", "left"],
      accuracy = 1e-0, f = floor
    ),
    max_day = plyr::round_any(
      x = m_senior$bws["b", "right"],
      accuracy = 1e-0, f = ceiling
    ),
    winner = TRUE,
    verbose = TRUE
  )

  # permutation analysis plot winners
  p2_seniors <- permutation_plot(
    permutation.out = m2_seniors,
    title = "Electoral Winners Senior Coalition Partner Voters"
  )

  # losers
  message("Permutation analysis junior coalition partner voters")
  m2_juniors <- permutation_analysis(
    data = df_winners_junior,
    min_day = plyr::round_any(
      x = -m_junior$bws["b", "left"],
      accuracy = 1e-0, f = floor
    ),
    max_day = plyr::round_any(
      x = m_junior$bws["b", "right"],
      accuracy = 1e-0, f = ceiling
    ),
    winner = FALSE,
    verbose = TRUE
  )

  # permutation analysis plot losers
  p2_juniors <- permutation_plot(
    permutation.out = m2_juniors,
    title = "Electoral Winners Junior Coalition Partner Voters"
  )

  # arrange plots
  p <- ggpubr::ggarrange(
    widths = c(1, 1),
    p_senior$rdplot, p2_seniors, p_juniors$rdplot, p2_juniors,
    ncol = 2, nrow = 2
  )

  ggplot2::ggsave(
    filename = "./figures/senior_junior_coalition_winners.png",
    device = "png",
    width = 24,
    height = 19,
    units = "cm",
    dpi = 600
  )

  ## seniors plot
  # arrange plots
  p <- ggpubr::ggarrange(
    widths = c(1, 1),
    p_senior$rdplot, p2_seniors,
    ncol = 2, nrow = 1
  )

  ggplot2::ggsave(
    filename = "./figures/robustness_seniors.png",
    device = "png",
    width = 18,
    height = 12,
    units = "cm",
    dpi = 600
  )

  ## losers plot
  # arrange plots
  p <- ggpubr::ggarrange(
    widths = c(1, 1),
    p_juniors$rdplot, p2_juniors,
    ncol = 2, nrow = 1
  )

  ggplot2::ggsave(
    filename = "./figures/robustness_juniors.png",
    device = "png",
    width = 18,
    height = 12,
    units = "cm",
    dpi = 600
  )

}